<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-demo__hzpasswordreset}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.address" placeholder="地址" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="address" label="地址" header-align="center" align="center"></el-table-column>
        <el-table-column prop="appAccount" label="app账号" header-align="center" align="center"></el-table-column>
        <el-table-column prop="pcAccount" label="pc账号" header-align="center" align="center"></el-table-column>
        <el-table-column prop="status" label="状态" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status === 1" size="small" type="warning">待审核</el-tag>
            <el-tag v-if="scope.row.status === 2" size="small" type="success">通过</el-tag>
            <el-tag v-if="scope.row.status === 3" size="small" type="danger">拒绝</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="时间" header-align="center" align="center"></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="scope.row.status === 1" type="success" size="small" @click="checkSuccess(scope.row.id)">{{ $t('passwordreset.status2') }}</el-button>
            <el-button v-if="scope.row.status === 1" type="danger"  size="small" @click="checkFail(scope.row.id)">{{ $t('passwordreset.status3') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/hz/passwordreset/page',
        getDataListIsPage: true,
        exportURL: '/demo/hzpasswordreset/export',
        deleteURL: '/demo/hzpasswordreset',
        deleteIsBatch: true,
        checkSuccess:'/hz/passwordreset/success/',
        checkFail:'/hz/passwordreset/fail/'
      },
      dataForm: {
        id: '',
        address:''
      }
    }
  },
  components: {
  },
    methods: {
        checkSuccess(id) {

            this.$confirm(this.$t('prompt.info', {'handle': this.$t('passwordreset.status2')}), this.$t('prompt.title'), {
                confirmButtonText: this.$t('confirm'),
                cancelButtonText: this.$t('cancel'),
                type: 'warning'
            }).then(() => {
                this.$http['get'](`${this.mixinViewModuleOptions.checkSuccess}` + id).then(({ data: res }) => {
                    if (res.code !== 0) {
                        return this.$message.error(res.msg)
                    }
                    this.$message({
                        message: this.$t('prompt.success'),
                        type: 'success',
                        duration: 500,
                        onClose: () => {
                            this.query()
                        }
                    })
                }).catch(() => {
                })
            }).catch(() => {
            })
        },
        checkFail(id) {

            this.$confirm(this.$t('prompt.info', {'handle': this.$t('passwordreset.status3')}), this.$t('prompt.title'), {
                confirmButtonText: this.$t('confirm'),
                cancelButtonText: this.$t('cancel'),
                type: 'warning'
            }).then(() => {
                this.$http['get'](`${this.mixinViewModuleOptions.checkFail}` + id).then(({ data: res }) => {
                    if (res.code !== 0) {
                        return this.$message.error(res.msg)
                    }
                    this.$message({
                        message: this.$t('prompt.success'),
                        type: 'success',
                        duration: 500,
                        onClose: () => {
                            this.query()
                        }
                    })
                }).catch(() => {
                })
            }).catch(() => {
            })
        }
    }
}
</script>
